<html>
	<head>
		<title>PBR Path Tracing - LDraw Models</title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

		<style>
			html, body {
				margin: 0;
				padding: 0;
				background-color: #111;
			}

			#info {
				position: absolute;
				bottom: 0;
				left: 0;
				font-family: 'Courier New', Courier, monospace;
				color: white;
				pointer-events: none;
			}

			#samples, #credits {

				opacity: 0.5;
				background-color: rgba( 0.0, 0.0, 0.0, 0.5 );
				padding: 5px;
				display: inline-block;

			}

			#loading {
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				color: white;
				font-family: 'Courier New', Courier, monospace;
			}

			a {
				color: white;
				pointer-events: all;
			}

			.checkerboard {
				background-image:
					linear-gradient(45deg, #222 25%, transparent 25%),
					linear-gradient(-45deg, #222 25%, transparent 25%),
					linear-gradient(45deg, transparent 75%, #222 75%),
					linear-gradient(-45deg, transparent 75%, #222 75%);
				background-size: 20px 20px;
				background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
			}
		</style>

	</head>
	<body>
		<div id="loading">LOADING</div>
		<div id="info">
			<div>
				<div id="samples">--</div>
			</div>
			<div>
				<div id="credits">--</div>
			</div>
		</div>
		<script type="module">

			function mecaBricksGoldCorrection( model ) {

				model.traverse( c => {

					if ( c.material ) {

						if ( c.material.color.getHexString() === '7f4c0e' ) {

							c.material.color.set( 0xc2801f ).multiplyScalar( 0.9 );
							c.material.roughness = 0.45;
							c.material.metalness = 0.6;

						} else if ( c.material.color.getHexString() === '613708' )  {

							c.material.color.set( 0xc2801f );
							c.material.color.g *= 0.75;
							c.material.color.b *= 0.75;
							c.material.roughness = 0.45;
							c.material.metalness = 0.6;

						}

					}

				} );

			}

			const MODEL_LIST = {

				'X-Wing': {
					opacityToTransmission: true,
					ior: 1.4,
					url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/ldraw/officialLibrary/models/7140-1-X-wingFighter.mpd_Packed.mpd',
				},

				'UCS AT-ST': {
					opacityToTransmission: true,
					ior: 1.4,
					url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/ldraw/officialLibrary/models/10174-1-ImperialAT-ST-UCS.mpd_Packed.mpd',
				},

				'Death Star': {
					opacityToTransmission: true,
					ior: 1.4,
					url: 'https://raw.githubusercontent.com/gkjohnson/ldraw-parts-library/master/models/10143-1 - Death Star II.mpd',
					rotation: [ Math.PI, Math.PI + 1.75 * Math.PI / 4, 0 ],
				},

				'Lunar Vehicle': {
					opacityToTransmission: true,
					ior: 1.4,
					url: 'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/ldraw/officialLibrary/models/1621-1-LunarMPVVehicle.mpd_Packed.mpd',
					rotation: [ Math.PI, - Math.PI / 2, 0 ],
				},

				'MecaBricks Auspicious Dragon': {
					url: 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/mecabricks/auspicious-dragon.dae',
					postProcess: mecaBricksGoldCorrection,
					credit: 'Model courtesy of <a href="https://mecabricks.com/">MecaBricks library</a>.',

				},

				'MecaBricks NASA Mars Rover': {
					url: 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/mecabricks/nasa-mars-curiosity-rover.dae',
					postProcess: mecaBricksGoldCorrection,
					credit: 'Model courtesy of <a href="https://mecabricks.com/">MecaBricks library</a>.',
				},

				'MecaBricks Apollo 11 Lander': {
					url: 'https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/mecabricks/apollo-11-lunar-lander/lunar-lander.dae',
					postProcess: mecaBricksGoldCorrection,
					credit: 'Model courtesy of <a href="https://mecabricks.com/">MecaBricks library</a>.',
				},

			};

			const modelNames = [
				'10019 - Rebel Blockade Runner - UCS.mpd',
				'10030-1 - Imperial Star Destroyer - UCS.mpd',
				'10129-1 - Rebel Snowspeeder - UCS.mpd',
				'10134-1 - Y-wing Attack Starfighter - UCS.mpd',
				'10143-1 - Death Star II.mpd',
				'10156-1 - LEGO Truck.mpd',
				'10179-1 - Millennium Falcon - UCS.mpd',
				'10182-1 - Cafe Corner.mpd',
				'10212-1 - Imperial Shuttle - UCS.mpd',
				'10213-1 - Shuttle Adventure.mpd',
				'10214-1 - Tower Bridge.mpd',
				'10220 - Volkswagen T1 Camper Van.mpd',
				'10224 - Town Hall.mpd',
				'10227-1 - B-wing Starfighter.mpd',
				'10240-1 - Red Five X-Wing Starfighter.mpd',
				'1180-1 - Space Port Moon Buggy.mpd',
				'1713-1 - Shipwrecked Pirate.mpd',
				'1789-1 - Star Hawk II.mpd',
				'1793-1 - Space Station Zenon.mpd',
				'21019-1 - Eiffel Tower.mpd',
				'21022-1 - Lincoln Memorial.mpd',
				'21028-1 - New York City.mpd',
				'21041-1 - Great Wall of China.mpd',
				'21043-1 - San Francisco.mpd',
				'21303 - WALLE.mpd',
				'21307 - Caterham Seven 620R.mpd',
				'21309-1 - NASA Apollo Saturn V.mpd',
				'21311 - Voltron - Voltron.mpd',
				'21318 - Tree House.mpd',
				'21321 - International Space Station.mpd',
				'21325 - Medieval Blacksmith.mpd',
				'40448 - Vintage Car.mpd',
				'5542 - Black Thunder.mpd',
				'5571-1 - Giant Truck.mpd',
				'5920-1 - Island Racer.mpd',
				'5934 - Dino Explorer.mpd',
				'6066 - Camouflaged Outpost.mpd',
				'6071 - Forestmens Crossing.mpd',
				'6080 - Kings Castle.mpd',
				'6232-1 - Skeleton Crew.mpd',
				'6235 - Buried Treasure.mpd',
				'6245 - Harbor Sentry.mpd',
				'6279-1 - Skull Island.mpd',
				'6285 - Black Seas Barracuda.mpd',
				'6286 - Skulls Eye Schooner.mpd',
				'6712-1 - Sheriff\'s Showdown.mpd',
				'6716-1 - Covered Wagon.mpd',
				'6718 - Raindance Ridge.mpd',
				'6755-1 - Sheriff\'s Lock-Up.mpd',
				'6761-1 - Bandit\'s Secret Hide-Out.mpd',
				'6799-1 - Showdown Canyon - Carriage.mpd',
				'6814-1 - Ice Tunnelator.mpd',
				'6831-1 - Message Decoder.mpd',
				'6835-1 - Saucer Scout.mpd',
				'6852-1 - Sonar Security.mpd',
				'6861-1 - X1 Patrol Craft.mpd',
				'6861-2 - Super Model Building Instruction.mpd',
				'6862-1 - Secret Space Voyager.mpd',
				'6879-1 - Blizzard Baron.mpd',
				'6886-1 - Galactic Peace Keeper.mpd',
				'6887-1 - Allied Avenger.mpd',
				'6898-1 - Ice-Sat V.mpd',
				'6923-1 - Particle Ionizer.mpd',
				'6955-1 - Space Lock-Up Isolation Base.mpd',
				'6956-1 - Stellar Recon Voyager.mpd',
				'6957-1 - Solar Snooper.mpd',
				'6959-1 - Lunar Launch Site.mpd',
				'6973-1 - Deep Freeze Defender.mpd',
				'6983-1 - Ice Station Odyssey.mpd',
				'70814 - Emmets Constructo-Mech.mpd',
				'70816 - Bennys Spaceship Spa_kOdSy6E.mpd',
				'7131-1 - Anakin\'s Podracer.mpd',
				'7150-1 - TIE Fighter & Y-wing.mpd',
				'7181 - TIE Interceptor - UCS.mpd',
				'7191 - X-wing Fighter - UCS.mpd',
				'7326-1 - Rise of the Sphinx.mpd',
				'7327-1 - Scorpion Pyramid.mpd',
				'7410-1 - Jungle River.mpd',
				'75053-1 - The Ghost.mpd',
				'75060 - Slave I.mpd',
				'75144 - Snowspeeder.mpd',
				'7784 - The Batmobile Ult_V1hXfMw.mpd',
				'928-1 - Galaxy Explorer.mpd',
				'9476-1 - The Orc Forge.mpd',

				// From Eurobricks forum post.
				// Commented items do not load or are uninteresting
				// '10029 - Lunar Lander.mpd',
				// '6919 - Planetary Prowler.mpd',
				// '21109 - Exo Suit.mpd',
				// '75827 - GHOSTBUSTERS HQ .mpd',
				// '1788 - Treasure Chest.mpd',
				// '6264 - Forbidden Cove.mpd',
				// '6246 - Crocodile Cage.mpd',
				// '6278 6292 - Enchanted Island.mpd',
				// '6256 - Island Catamaran.mpd'
				'6907 - Sonic Stinger.mpd',
				'10228 - HAUNTED HOUSE.mpd',
				'10252 - Volkswagen Beetle.mpd',
				'6969 - Celestial Stinger.mpd',
				'21103 - The DeLorean time machine.mpd',
				'6977 - Arachnoid Atar Base.mpd',
				'6905 - Biwing Blaster.mpd',

			];

			modelNames.forEach( name => {

				const cleanedName = name.replace( /.+?\s-\s/, '' ).replace( /\.mpd$/, '' );
				if ( ! ( cleanedName in MODEL_LIST ) ) {

					MODEL_LIST[ cleanedName ] = {

						opacityToTransmission: true,
						ior: 1.4,
						url: `https://raw.githubusercontent.com/gkjohnson/ldraw-parts-library/master/models/${ name }`,

					};

				}

			} );

			for ( const key in MODEL_LIST ) {

				const info = MODEL_LIST[ key ];
				if ( ! info.credit ) {

					info.credit = 'Model courtesy of the <a href="https://omr.ldraw.org/">LDraw Official Model Repository and Parts Library</a>.';

				}

			}

			window.MODEL_LIST = MODEL_LIST;
		</script>
		<script src="./index.js" type="module"></script>
	</body>
</html>
